package cn.swust.designpatternlearningplatform.common.utils;

import cn.swust.designpatternlearningplatform.domain.bo.TokenInfoBo;
import cn.swust.designpatternlearningplatform.domain.dto.TopicDto;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TopicHelpContext {
    private final static ThreadLocal<Map<Integer, List<TopicDto>>> TOPIC_HELP = new ThreadLocal<>();
    public static void newMap() {
        TOPIC_HELP.set(new HashMap<>());
    }
    public static List<TopicDto> get(Integer pointId) {
        Map<Integer, List<TopicDto>> integerListMap = TOPIC_HELP.get();
        if (integerListMap == null) {
            return null;
        }
        return integerListMap.get(pointId);
    }
    public static Map<Integer,List<TopicDto>> get() {
        return TOPIC_HELP.get();
    }
    public static void set(Integer pointId,List<TopicDto> topicDtoList) {
        Map<Integer, List<TopicDto>> integerListMap = get();
        if(integerListMap == null) {
            integerListMap = new HashMap<>();
            TOPIC_HELP.set(integerListMap);
        }
        integerListMap.put(pointId,topicDtoList);
    }
    public static void clear() {
        if (TOPIC_HELP.get() != null) {
            TOPIC_HELP.remove();
        }
    }
}
